package com.bailugansan.efficiencyboard.utils;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

/**
 * @author BailuGansan
 */
public class Druid {
    private static DruidDataSource ds = null;

    static { // 获取Druid线程池
        Properties pros = new Properties();
        InputStream ras = ClassLoader.getSystemClassLoader().getResourceAsStream("Druid.properties");
        try {
            pros.load(ras);
            ds = (DruidDataSource) DruidDataSourceFactory.createDataSource(pros);
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    public static Connection getConnection(){
        Connection conn;

        try {
            conn = ds.getConnection();
            return conn;
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return null;
    }
}
